package com.aletto.general_store.ui.activities;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.aletto.general_store.R;
import com.aletto.general_store.data.DataRepository;
import com.aletto.general_store.presenters.AddAddressTemplate;
import com.aletto.general_store.utils.XHelper;
import com.sisyphus.spinach.utils.watchers.EmptyRule;
import com.sisyphus.spinach.utils.watchers.OnWatcherCallback;
import com.sisyphus.spinach.utils.watchers.TextWatchers;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * 添加地址
 */
public class AddressAddActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_address);
        XHelper.initTitle(this, R.string.add_address);

        EditText nameEdit = findViewById(R.id.name_edit);
        EditText phoneEdit = findViewById(R.id.phone_edit);
        EditText addressDetailsEdit = findViewById(R.id.address_details_edit);
        Button confirmButton = findViewById(R.id.confirm_button);

        TextWatchers.add(new EmptyRule(nameEdit), new EmptyRule(phoneEdit), new EmptyRule(addressDetailsEdit))
                .setWatcherCallback(confirmButton::setEnabled);

        confirmButton.setOnClickListener(v ->
                new AddAddressTemplate(findViewById(R.id.layout_parent)).execute(getLifecycle()));
    }

}
